import java.io.PrintWriter;
import java.util.HashMap;

class ConditionalStatement extends Statement {

	private Node exp_;
	private Node stat_list_if_;
	private Node stat_list_else_;

	public ConditionalStatement(Node e, Node ss1, Node ss2) {
		exp_ = e;
		stat_list_if_ = ss1;
		stat_list_else_ = ss2;
	}

	public ConditionalStatement(Node e, Node ss) {
		exp_ = e;
		stat_list_if_ = ss;
	}

	@Override
	public void print(PrintWriter pw) {
		pw.println("Node name : ConditionalStatement");
		// assert( exp_ && stat_list_if_);
		exp_.print(pw);
		if (stat_list_if_ != null) {
			stat_list_if_.print(pw);
		}
		if (stat_list_else_ != null) {
			stat_list_else_.print(pw);
		}
	}

	public String translate(HashMap<String, PrintWriter> pws, String pare, SymbolTable rt,
			String parent) {
		String key = rt.getStack().get(1);
		PrintWriter pw = pws.get(key);
		printIndent(pw, rt.getLevel());
		
		if (stat_list_else_ != null) {
			pw.print("if(");
			exp_.translate(pws, null, rt, parent);
			pw.print(")");
			rt.getStack().push("if");
			System.out.println("condition pushed: if");
			stat_list_if_.translate(pws, null, rt, parent);
			rt.getStack().push("else");
			System.out.println("condition pushed: else");
			pw.print("else");
			stat_list_else_.translate(pws, null, rt, parent);
		} else {
			pw.print("if(");
			exp_.translate(pws, null, rt, parent);
			pw.print(")");
			rt.getStack().push("if");
			System.out.println("condition pushed: if");
			stat_list_if_.translate(pws, null, rt, parent);
		}
		return null;
	}

}
